<template>
	<view>
		<div id="app">
			<div id="set_data">
				<div class="fill_word">
					<ul>
						<li>
							<div class="am-form-group"><i class="fa fa-plus-square-o" style="font-size:24px"></i>
								<input type="text" name="required" data-required="请输入用户姓名" class="mdn-input"
									v-model="fd.name" placeholder="用户真实姓名">
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-plus-square-o" style="font-size:24px"></i>
								<input type="text" name="required" data-required="请输入用户性别" class="mdn-input"
									v-model="fd.sex" placeholder="用户性别">
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-plus-square" style="font-size:24px"></i>
								<input type="text" name="required" data-required="请输入紧急联系人姓名" class="mdn-input"
									v-model="fd.pname" placeholder="联系人姓名">
								<span class="mdn-bar"></span>
							</div>
						</li>

						<li>
							<div class="am-form-group"><i class="fa fa-plus-square" style="font-size:24px"></i>
								<input type="text" name="required" data-required="请输入紧急联系人性别" class="mdn-input"
									v-model="fd.psex" placeholder="联系人性别">
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-plus-square" style="font-size:24px"></i>
								<input type="text" name="name10" data-phone="请输入正确的手机号码" data-required="手机号码不能为空"
									class="mdn-input" v-model="fd.pphone" placeholder="联系人手机号码">
								<span class="mdn-bar"></span>
							</div>
						</li>
						<li>
							<div class="am-form-group"><i class="fa fa-plus-square" style="font-size:24px"></i>
								<input type="text" name="required" data-required="请输入紧急联系人住址" class="mdn-input"
									v-model="fd.paddress" placeholder="联系人住址">
								<span class="mdn-bar"></span>
							</div>
						</li>
					</ul>
					<li>
						<div style="color: red;">{{msg}}</div>
					</li>
				</div>
			</div>
		</div>
		<button type="button" id="submitBtn" @click="submit()" class="yes"
			style="background-color: #61ac85;border: 1px solid #579572;">保存</button>
		</div>
	</view>
</template>

<script>
	import config from '@/config'
	export default {
		data() {
			return {
				usr: '',
				pwd: '',
				fd: {
					name: "",
					sex: "",
					pname: "",
					psex: "",
					pphone: "",
					paddress: ""
				},
				msg: ''
			}
		},
		methods: {
			backset_up: function() {
				uni.navigateTo({ //跳转设置页面
					url: 'set_up',
				});
			},
			submit: function() {
				var that = this;
				if ((this.fd.name.split(" ").join("").length == 0) || !this.fd.name) {
					that.msg = "请填写用户姓名";
					return false;
				}
				if ((this.fd.pname.split(" ").join("").length == 0) || !this.fd.pname) {
					that.msg = "请填写联系人姓名";
					return false;
				}
				if ((this.fd.pphone.split(" ").join("").length != 11) || !this.fd.pphone) {
					that.msg = "请填写正确的手机号码";
					return false;
				}
				if ((this.fd.paddress.split(" ").join("").length == 0) || !this.fd.paddress) {
					that.msg = "请填写联系人地址";
					return false;
				}
				uni.request({
					url: `${config.baseUrl}/sos/sos?token=` + uni.getStorageSync('token'),
					method: 'POST',
					data: this.fd,
					success(r) {
						var that = this;
						if (r.data.succ) {
							// that.info = r.data.data;
							uni.showToast({
								title:r.msg
							})
							//console.log(r.data+"sucess");
							uni.navigateTo({
								url: 'set_up'
							})
						} else {
							//console.log("Wrong!")
						}
					}
				})
			},
		}
	}
</script>

<style>

</style>
